using System;
using System.Web.UI.HtmlControls;
using System.Web;
using System.Web.UI.WebControls;

namespace NET.Library.IO
{
	/// <summary>
	/// Summary description for File.
	/// </summary>
	public class FileSystem
	{
		/// <summary>
		/// 
		/// </summary>
		public FileSystem()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="UploadFile"></param>
		/// <param name="UploadPath"></param>
		/// <returns></returns>
		public static string Save(HtmlInputFile UploadFile, string UploadPath)
		{
			string strFileNameOnly, strPath;
			int intFileNameLength;
			string strFilename = UploadFile.PostedFile.FileName;

			intFileNameLength = strFilename.LastIndexOf("\\"); 
			strFileNameOnly = strFilename.Substring(intFileNameLength + 1); 
			strPath = HttpContext.Current.Server.MapPath(UploadPath + strFileNameOnly);
			UploadFile.PostedFile.SaveAs(strPath);
				
			//			if (File.Exists(strPath))
			//			{
			//				return true;
			//			}
			//			else
			//			{
			//				return false;
			//			}
			return strFileNameOnly;
		}

        /// <summary>
        /// 
        /// </summary>
        /// <param name="UploadFile"></param>
        /// <param name="UploadPath"></param>
        /// <returns></returns>
        public static string Save(FileUpload UploadFile, string UploadPath)
        {
            string fileNameOnly, path;
            int fileNameLength;
            string fileName = UploadFile.PostedFile.FileName;

            fileNameLength = fileName.LastIndexOf("\\");
            fileNameOnly = fileName.Substring(fileNameLength + 1);
            path = HttpContext.Current.Server.MapPath(UploadPath + fileNameOnly);
            UploadFile.PostedFile.SaveAs(path);

            return fileNameOnly;
        }
	}
}
